local DB = require("app.utils.DB")

local ZoneDB = class("ZoneDB",DB)

function ZoneDB:ctor()
	ZoneDB.super.ctor(self)
end

function ZoneDB:openWithFile(dbFile)
    ZoneDB.super.openWithFile(self,dbFile,true)
end


function ZoneDB:test()
	local ret = self:query("SELECT * FROM globalpars")
	dump(ret,"ZoneDB:test")
end

function ZoneDB:queryArenas()
    local sql = string.format("SELECT * FROM activity_arena where seasonID is null")
    local res = self:query(sql)
    return res
end

function ZoneDB:queryArenaSeasonByTime(curTime)
    local sql = string.format("SELECT * FROM activity_arena_season WHERE startTime <= %d AND endTime > %d",curTime,curTime)
    local config = self:querySingle(sql)
    return config
end

function ZoneDB:queryArenaSeasonById(seasonId)
    local sql = string.format("SELECT * FROM activity_arena_season WHERE ID = %d",seasonId)
    return self:querySingle(sql)
end

function ZoneDB:queryArenaSeasons()
    local sql = string.format("SELECT * FROM activity_arena_season")
    return self:query(sql)
end

function ZoneDB:queryArenaBySeasonIdAndType(seasonId,sType)
    local sql = string.format("SELECT * FROM activity_arena WHERE seasonID = %d AND type = %d",seasonId,sType)
    return self:querySingle(sql)
end

function ZoneDB:queryArenaBySeasonId(seasonId)
    local sql = string.format("SELECT * FROM activity_arena WHERE seasonID = %d",seasonId)
    local configs = self:query(sql)
    return configs
end

function ZoneDB:queryActivityShowByLevel(level)
    local sql = string.format("SELECT * FROM activity_show WHERE minLevel <= %d and maxLevel >= %d",level,level)
    local activityShow = self:querySingle(sql)
    return activityShow
end

function ZoneDB:queryActivityByPos(position)
	local sql = string.format("SELECT * FROM activity_total WHERE position = " .. position)
	local activityConfig = self:querySingle(sql)
	return activityConfig
end

function ZoneDB:queryActivityById(id)
	local sql = string.format("SELECT * FROM activity_total WHERE ID = " .. id)
	local activityConfig = self:querySingle(sql)
	return activityConfig
end

function ZoneDB:queryActivityByCalendarShow(showType)
    local sql = string.format("SELECT * FROM activity_total WHERE calendarshow = " .. showType)
    local activitys = self:query(sql)
    return activitys
end

function ZoneDB:queryActivityByType(type)
    local sql = string.format("SELECT * FROM activity_total WHERE type = " .. type)
    local activitys = self:query(sql)
    return activitys
end

function ZoneDB:queryActivityByTypes(types)
    local sql = string.format("SELECT * FROM activity_total WHERE type in " .. types)
    local activitys = self:query(sql)
    return activitys
end

function ZoneDB:queryActivitiesByActivityNpcId()
    local sql = string.format("SELECT * FROM activity_total WHERE activityNpcId is not NULL ")
    local activitys = self:query(sql)
    return activitys
end

function ZoneDB:queryActivitiesByScript()
    local sql = string.format("SELECT * FROM activity_total WHERE script is not NULL ")
    local activitys = self:query(sql)
    return activitys
end

function ZoneDB:queryActivitiesByShowWeekType(showType)
    local sql = string.format("SELECT * FROM activity_total WHERE calendarshowweek = " .. showType)
    local activitys = self:query(sql)
    return activitys
end

function ZoneDB:queryActivitys()
	local sql = string.format("SELECT * FROM activity_total")
	local activitys = self:query(sql)
	return activitys
end

function ZoneDB:queryTheATresById(actId)
    local sql = string.format("SELECT * FROM activity_theatre WHERE ID=%d", actId)
    local res = self:querySingle(sql)
    return res
end

function ZoneDB:querySignRewardsByYearAndMonth(year,month)
    local sql = string.format("SELECT * FROM signReward WHERE year = %s and month = %s",year,month)
    local signRewardsConfig = self:query(sql)
    return signRewardsConfig
end

function ZoneDB:querySignRewardsByYearAndMonth(year,month)
    local sql = string.format("SELECT * FROM signReward WHERE year = %s and month = %s",year,month)
    local signRewardsConfig = self:query(sql)
    return signRewardsConfig
end

function ZoneDB:queryLoginReward(id)
    local sql = string.format("SELECT * FROM login_reward WHERE ID=%d", id)
    local result = self:querySingle(sql)
    return result
end

return ZoneDB
